@using CodeGenerator
@using RazorLight
@using BXJG.Common;
@using BXJG.Common.Extensions;
@inherits TemplatePage<ExecuteContext>
@{
    DisableEncoding = true;//禁止html编码，因为我们是做代码生成器
}
using @(Model.Model.CoreNamespace);
using @(Model.Model.CoreShareNamespace);
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace @(Model.Model.EFNamespace)
{
    /// <summary>
    /// @(Model.Model.DisplayName) ef映射
    ///</summary>
    public partial class EFMap : IEntityTypeConfiguration<@(Model.Model.EntityName)>
    {
        public void Configure(EntityTypeBuilder<@(Model.Model.EntityName)> builder)
        {
            //表名称
            builder.ToTable("@(Model.Name)_@(Model.Model.Name)",t=>t.HasComment("@(Model.Model.DisplayName)"));

@if(Model.Model.IsTree)
{
            @:builder.MapGeneralTree();
}
@foreach (var field in Model.Model.NormalFields)
{
            @:/// <summary>
            @:/// @(field.DisplayName)
            @:///</summary>
            @:var @(field.Name) = builder.Property(x => x.@(field.Name));
            @:@(field.Name).HasComment("@(field.DisplayName)");
    if(field.Length>0){
            @:@(field.Name).HasMaxLength(@(field.CoreShareConstsMaxLength));
    }
    if(field.CSharpType=="string"){
            @:@(field.Name).IsUnicode(@(field.IsUnicode.ToString().ToLower()));
    }
            @:@(field.Name).IsRequired(@(field.IsRequired.ToString().ToLower()));
}
        }
    }
}